def searchInsert(nums, target):
    """
    :type nums: List[int]
    :type target: int
    :rtype: int
    """
    if not nums:
        return 0
    left, right = 0, len(nums) - 1
    if target > nums[right]:
        return len(nums)
    while (left <= right - 1):
        mid = left + (right - left) // 2
        if nums[mid] == target:
            return mid
        elif nums[mid] > target:
            right = mid
        else:
            left = mid + 1
    return left


nums = [-1, 0, 3, 5, 9, 12]
target = 4
print(searchInsert(nums, target))
